package com.dlc.shop.systemtest.api.amount;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dlc.shop.bean.model.ShopWithdrawCash;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;

import java.util.List;

/**
 * @author lanhai
 */
public class ShopWithdrawCashApi {

    public static ShopWithdrawCash getShopInfo(){
        String url = Constant.SHOP_URL+"/shop/withdrawCash/getShopInfo";
        return HttpUtil.get(url,ShopWithdrawCash.class);
    }

    public static void apply(ShopWithdrawCash shopWithdrawCash){
        String url = Constant.SHOP_URL+"/shop/withdrawCash/apply";
        HttpUtil.post(url,shopWithdrawCash);
    }


    public static void audit(ShopWithdrawCash shopWithdrawCash){
        String url = Constant.PLATFORM_URL+"/shop/shopWithdrawCash/audit";
        HttpUtil.put(url,shopWithdrawCash);
    }

    /**
     * 获取最新的一条提现申请
     * @param amount
     * @return
     */
    public static ShopWithdrawCash getShopWithdrawCash(Double amount){
        String url = Constant.SHOP_URL+"/shop/withdrawCash/page?amount=" +amount;
        Object result = HttpUtil.get(url, Object.class);
        JSONObject jsonObject = JSON.parseObject(result.toString());
        Object records = jsonObject.get("records");
        List<ShopWithdrawCash> shopWithdrawCashes = JSON.parseArray(records.toString(), ShopWithdrawCash.class);
        return shopWithdrawCashes.get(0);
    }
}
